package drone.basis.express ;

import com.googlecode.aviator.runtime.function.AbstractFunction ;
import com.googlecode.aviator.runtime.function.FunctionUtils ;
import com.googlecode.aviator.runtime.type.AviatorDouble ;
import com.googlecode.aviator.runtime.type.AviatorObject ;

import java.util.Map ;

public class FuncS48 extends AbstractFunction
{

	@Override
	public AviatorObject call (
			Map < String , Object > env ,
			AviatorObject arg1 ,
			AviatorObject arg2 ,
			AviatorObject arg3 ,
			AviatorObject arg4 ,
			AviatorObject arg5 ,
			AviatorObject arg6
	)
	{
		byte b1 = FunctionUtils.getNumberValue ( arg1 , env ).byteValue ( ) ;
		byte b2 = FunctionUtils.getNumberValue ( arg2 , env ).byteValue ( ) ;
		byte b3 = FunctionUtils.getNumberValue ( arg3 , env ).byteValue ( ) ;
		byte b4 = FunctionUtils.getNumberValue ( arg4 , env ).byteValue ( ) ;
		byte b5 = FunctionUtils.getNumberValue ( arg5 , env ).byteValue ( ) ;
		byte b6 = FunctionUtils.getNumberValue ( arg6 , env ).byteValue ( ) ;
		long tmp ;
		if ( ( b1 & 0x80 ) > 0 )
		{
			b1 = ( byte ) ~ b1 ;
			b2 = ( byte ) ~ b2 ;
			b3 = ( byte ) ~ b3 ;
			b4 = ( byte ) ~ b4 ;
			b5 = ( byte ) ~ b5 ;
			b6 = ( byte ) ~ b6 ;

			long lb1 = b1 & 0xff ;
			long lb2 = b2 & 0xff ;
			long lb3 = b3 & 0xff ;
			long lb4 = b4 & 0xff ;
			long lb5 = b5 & 0xff ;
			long lb6 = b6 & 0xff ;

			tmp = lb1 * 1099511627776L + lb2 * 4294967296L + lb3 * 16777216L + lb4 * 65536 + lb5 * 256 + lb6 + 1 ;
			tmp = - 1 * tmp ;
		} else
		{
			long lb1 = b1 & 0xff ;
			long lb2 = b2 & 0xff ;
			long lb3 = b3 & 0xff ;
			long lb4 = b4 & 0xff ;
			long lb5 = b5 & 0xff ;
			long lb6 = b6 & 0xff ;

			tmp = lb1 * 1099511627776L + lb2 * 4294967296L + lb3 * 16777216L + lb4 * 65536 + lb5 * 256 + lb6 ;
		}
		return new AviatorDouble ( ( double ) tmp ) ;
	}

	public String getName ( )
	{
		return "s48" ;
	}
}
